home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PORTABLE.ZIP / NEWPAD.C < prev    next >
Text File  |  1992-11-21  |  4KB  |  99 lines

  1. #define        CURSES_LIBRARY  1
  2. #include <curses.h>
  3. #undef newpad
  4.  
  5. #ifndef        NDEBUG
  6. char *rcsid_newpad = "$Header: c:/curses/portable/RCS/newpad.c%v 2.0 1992/11/15 03:29:27 MH Rel $";
  7. #endif
  8.  
  9.  
  10.  
  11.  
  12. /*man-start*********************************************************************
  13.  
  14.   newpad()     - Create new pad
  15.  
  16.   X/Open Description:
  17.        Creates a new pad data structure.  A pad is a special case of a
  18.        window, which is not restricted by the screen size, and is not
  19.        necessarily associated with a particular part of the screen.  A
  20.        pad can be used when a large window is needed, and only a part
  21.        of the window will be on the screen at one tme.  Automatic
  22.        refreshes of pads (e.g., from scrolling or echoing of input) do
  23.        not occur.  It is not legal to call refresh() with a pad as an
  24.        argument; the routines prefresh() or pnoutrefresh() should be
  25.        called instead.  Note that these routines require additional
  26.        parameters to specify the part of the pad to be displayed and
  27.        the location on the screen to be used for display.
  28.  
  29.   PDCurses Description:
  30.        PDCurses (as a library) provides the developer with the ability to
  31.        hook in their own malloc debugging  package.  See the details in
  32.        INITSCR.C for details on how to accomplish this.
  33.  
  34.   X/Open Return Value:
  35.        The newpad() function returns a pointer to the new WINDOW structure
  36.        created on success and returns a null pointer on error.
  37.  
  38.   X/Open Errors:
  39.        No errors are defined for this function.
  40.  
  41.   Portability:
  42.        PDCurses        WINDOW* newpad( int nlines, int ncols );
  43.        X/Open Dec '88  WINDOW* newpad( int nlines, int ncols );
  44.        BSD Curses      WINDOW* newpad( int nlines, int ncols );
  45.        SYS V Curses    WINDOW* newpad( int nlines, int ncols );
  46.  
  47. **man-end**********************************************************************/
  48.  
  49. WINDOW* newpad( int nlines, int ncols )
  50. {
  51. extern void*   (*mallc)( size_t );
  52. extern void*   (*callc)( size_t, size_t );
  53. extern void    (*fre)( void* );
  54.  
  55.        WINDOW* win;
  56.        chtype* ptr;
  57.        int     i;
  58.        int     j;
  59.  
  60.        if ((win = PDC_makenew( nlines, ncols, -1, -1 )) == (WINDOW *)NULL)
  61.                return( (WINDOW *)NULL );
  62.  
  63.        for (i = 0; i < nlines; i++)
  64.        {
  65.                /*
  66.                 * make and clear the lines
  67.                 */
  68.                if ((win->_y[i] = (*callc)(ncols, sizeof(chtype))) == NULL)
  69.                {
  70.                        for (j = 0; j < i; j++)
  71.                        {
  72.                                /*
  73.                                 * if error, free all the data
  74.                                 */
  75.                                (*fre)(win->_y[j]);
  76.                        }
  77.                        (*fre)(win->_firstch);
  78.                        (*fre)(win->_lastch);
  79.                        (*fre)(win->_y);
  80.                        (*fre)(win);
  81.                        return( (WINDOW *)NULL );
  82.                }
  83.                else
  84.                {
  85.                        for (ptr = win->_y[i];
  86.                             ptr < win->_y[i] + ncols;)
  87.                        {
  88.                                /*
  89.                                * Retain the original screen attributes...
  90.                                */
  91.  
  92.                                *ptr++ = _cursvar.blank;        
  93.                        }
  94.                }
  95.        }
  96.        win->_flags = _PAD;
  97.        return( win );
  98. }
  99.